import { concat } from "ethers/lib/utils";
import {testNetWork} from "./env"
import { ethers, utils } from "ethers";
export async function contractInteraction() {
    const main = async () => {
      // 创建 provider 实例
      const providerTest = new ethers.providers.JsonRpcProvider(testNetWork) 
      // 创建 钱包实例 实例
      const privateKey = '5e34716a60a0926d67c629fae8752cdc9fbe742095a093d40e5b1a2834cc981e'
      const wallet = new ethers.Wallet(privateKey,providerTest)
      // 创建可读写合约
      const contractAddress = '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6'
      const abi = [
        "function balanceOf(address) public view returns(uint)",
        "function deposit() public payable",
        "function transfer(address, uint) public returns (bool)",
        "function withdraw(uint) public",
    ]
    const contractWETH = new ethers.Contract(contractAddress,abi,wallet) 
    // 1.通过合约实例查询账户余额
    const walletAddress =  await wallet.getAddress()
    const wethBalanceOf = await contractWETH.balanceOf(walletAddress)
    console.log('WETH钱包余额',ethers.utils.formatEther(wethBalanceOf))
    // 2. 将账户的ETH转成WETH
   const tx =  await contractWETH.deposit({value: ethers.utils.parseEther("0.1")})
   await tx.wait()
    const wethBalanceOf1 = await contractWETH.balanceOf(walletAddress)
    console.log('ETH转了0.1WETH 后的钱包余额',ethers.utils.formatEther(wethBalanceOf1))
    }
    main()
}